package com.foodconflict.action;

import java.util.List;

import com.foodconflict.domain.Conflict;
import com.foodconflict.domain.Food;
import com.foodconflict.service.FoodService;
import com.foodconflict.util.ActionBase;
import com.foodconflict.util.PagedData;
import com.foodconflict.util.PagedResult;

public class FoodModelAction extends ActionBase  {
	private FoodService foodService;
	private Food food;
	private PagedData pageData;
	private int pageindex;
	private List<Conflict> result;
	
	public FoodService getFoodService() {
		return foodService;
	}
	public void setFoodService(FoodService foodService) {
		this.foodService = foodService;
	}
	public Food getFood() {
		return food;
	}
	public void setFood(Food food) {
		this.food = food;
	}
	
	public PagedData getPageData() {
		return pageData;
	}
	public void setPageData(PagedData pageData) {
		this.pageData = pageData;
	}
	public int getPageindex() {
		return pageindex;
	}
	public void setPageindex(int pageindex) {
		this.pageindex = pageindex;
	}
	public List<Conflict> getResult() {
		return result;
	}
	public void setResult(List<Conflict> result) {
		this.result = result;
	}
	public String insertNew()
	{
		if (food != null)
		{
		foodService.insertNew(food);
		return success("insertNew");
		}
		else
		{
			return "input";
		}
	}
	
	public String update()
	{
		foodService.update(food);
		return success("update");
	}
	
	public String delete()
	{
		foodService.delete(food.getFid());
		return success("delete");
	}
	
	public String showMe()
	{
		food = foodService.findFood(food.getFid());
		return success("showMe");
	}
	
	public String findConflictList()
	{
		PagedResult<Conflict> pr = foodService.findConflictList(food.getFid(), 20, pageindex);
		result = pr.getResultList();
		pageData = pr.getPagedData();
		return success("findConflictList");
	}
}
